﻿/*
 * 文件名称：
 * 程序员：yylu
 * 创建时间：2009
 * 
 * 功能说明：功能模块的地区控件
 * 
 * 修改人员：yylu
 * 
 * 修改日期：2009/08/20
 * 
 * 修改记录：1)增加控件手写单独使用的代码
 */


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class UserControls_FieldControl_AreaType : Whir.Controls.ModelField.BaseFieldControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Whir.BLL.Whir_FieldText bll = new Whir.BLL.Whir_FieldText();
        int fieldTextId = int.Parse(bll.GetList(" FieldID = " + this.FieldID).Tables[0].Rows[0][0].ToString());

        if (this.isSingleUse)
        {
            this.InitFieldControl(this.FieldID);
        }
                
        if (!IsPostBack)
        {
            int ItemID = NetRequest.GetQueryInt("ItemID");
            BindDDL(this.DropDownList1, "0");
            if (ItemID == 0)
            {
                //添加操作，绑定默认值            
            }
            else
            {
                //更新操作，绑定值
                string address = FieldCommon.GetBindValue(this.FieldID, ItemID);
                if (address.Split('|').Length > 0)
                {
                    DropDownList1.SelectedValue = address.Split('|')[0];
                    BindDDL(this.DropDownList2, DropDownList1.SelectedValue);
                    DropDownList2.SelectedValue = address.Split('|')[1];
                    BindDDL(this.DropDownList3, DropDownList2.SelectedValue);
                    DropDownList3.SelectedValue = address.Split('|')[2];
                }
            }
        }
        else
        {
            this.FieldValue = DropDownList1.SelectedValue + "|" + DropDownList2.SelectedValue + "|" + DropDownList3.SelectedValue;
        }
    }

    //绑定下拉列表
    protected void BindDDL(DropDownList ddl, string pid)
    {
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem("= 请选择 =", "-1"));

        string strSql = "";
        if (pid == "0")
            strSql = "select [CityName],cityID from ChinaArea where ParentID='100000'";
        else if (pid != "-1")
            strSql = "select [CityName],cityID from ChinaArea where ParentID='" + pid + "'";

        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(strSql).Tables[0];

        if (dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                ddl.Items.Add(new ListItem(dr["CityName"].ToString(), dr["cityID"].ToString()));
            }
            ddl.Visible = true;
        }
        else
        {
        }
    }

    protected void ddl1_Changed(object sender, EventArgs e)
    {
        BindDDL(this.DropDownList2, this.DropDownList1.SelectedValue);
    }

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindDDL(this.DropDownList3, this.DropDownList2.SelectedValue);
    }
}
